package com.zenith.edu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zenith.edu.mapper.EduWarningLogMapper;
import com.zenith.edu.po.domain.EduWarningLog;
import com.zenith.edu.po.dto.EduWarningLogDTO;
import com.zenith.edu.po.vo.EduWarningLogVO;
import com.zenith.edu.service.EduWarningLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EduWarningLogServiceImpl extends ServiceImpl<EduWarningLogMapper, EduWarningLog> implements EduWarningLogService {
    
    @Override
    public EduWarningLogVO createWarningLog(EduWarningLogDTO dto) {
        EduWarningLog warningLog = new EduWarningLog();
        BeanUtils.copyProperties(dto, warningLog);
        this.save(warningLog);
        
        EduWarningLogVO vo = new EduWarningLogVO();
        BeanUtils.copyProperties(warningLog, vo);
        return vo;
    }
    
    @Override
    public EduWarningLogVO getWarningLogById(Long id) {
        EduWarningLog warningLog = this.getById(id);
        if (warningLog == null) {
            return null;
        }
        
        EduWarningLogVO vo = new EduWarningLogVO();
        BeanUtils.copyProperties(warningLog, vo);
        return vo;
    }
    
    @Override
    public EduWarningLogVO updateWarningLog(EduWarningLogDTO dto) {
        EduWarningLog warningLog = new EduWarningLog();
        BeanUtils.copyProperties(dto, warningLog);
        this.updateById(warningLog);
        
        EduWarningLogVO vo = new EduWarningLogVO();
        BeanUtils.copyProperties(warningLog, vo);
        return vo;
    }
    
    @Override
    public boolean deleteWarningLog(Long id) {
        return this.removeById(id);
    }
    
    @Override
    public List<EduWarningLogVO> getWarningLogList() {
        List<EduWarningLog> warningLogList = this.list();
        return warningLogList.stream().map(warningLog -> {
            EduWarningLogVO vo = new EduWarningLogVO();
            BeanUtils.copyProperties(warningLog, vo);
            return vo;
        }).collect(Collectors.toList());
    }
}